﻿function ActivityDailog(activity ,popup,popupForm,dailogtitle) {
    this.popup = popup;
    this.popupForm = popupForm;
    this.DailogTitle = dailogtitle;
    this.Activity = activity;
    this.Fields = new Array();
    this.BuildFormHtml = function () {
        var html = "<div class='dailogForm'>";
        for (var i = 0; i < this.Fields.length; i++) {
            
            if ($(activity).is('[' + this.Fields[i].Id+ ']'))
                this.Fields[i].value = $(activity).attr(this.Fields[i].Id);
            html += this.Fields[i].GetHtml();
        }
        html += "</div>";
        return html;
    };
    
    this.Show = function ()
    {
        var popupForm = $(this.popupForm);
        var popup = $(this.popup);
        popup.html(this.BuildFormHtml());
        popupForm.dialog({ modal: true, width: 500, height: 400, title: this.DailogTitle });
        popupForm.dialog('open');
        $('#popform_save', popupForm).click(function ()
        {
            //start get input data and set activity attributes
            $(":input", popup).each(function () {
                activity.attr(this.name, $(this).val());
                //alert();
            });
            popupForm.dialog('close');
        });
    };
}
function DailogField(label, type, id, note) {
    this.Label = label;
    this.Type = type;
    this.Id = id;
    this.Note = note;
    this.value = "";
    this.GetHtml = function () {
        if (this.Id.length == 0)
            throw new Error("Id is empty");
        if (this.Type == 0)
            throw new Error("Field Type not defined");
        if (this.Label.length == 0)
            throw new Error("Field Label not defined");

        return "<label for=\""+this.Id+"\">"+this.Label+"</label><input type=\"text\" name=\"" + this.Id + "\" value=\""+this.value+"\" /><br/>";
    }
};

function ActivityForm(type) {
    this.ActivityType = type;
    this.Fields = new Array();
    this.LoadFields = function () {
        switch (this.ActivityType) {
            case "Task":
                this.Fields.push(new DailogField("Task Id", "input", "id", ""));
                this.Fields.push(new DailogField("Task Title", "input", "taskTitle", ""));
                this.Fields.push(new DailogField("Assigned To", "input", "userId", ""));
                this.Fields.push(new DailogField("Task Period", "input", "Period", "example 30min or 5 hours or 3days"));
                this.Fields.push(new DailogField("OutCome", "input", "TaskOutCome", "comma sperated value"));
                break;
            case "TaskDecision":
                this.Fields.push(new DailogField("Compare to OutCome", "input", "outCome", ""));
                break;
            default:
                break;
        }
    };
};
